Function CreateWeather . Weather( Camera )
	
	wea . Weather = New Weather
	
	wea \ Name$ = ""
	wea \ Amount = 1
	
	wea \ Camera = Camera
	
	For i = 0 To 50
		wea \ PatternTextures[ i ] = LoadTexture( "Muster" + i + ".png" , 2 )
	Next
	
	Return wea
	
End Function

Function CreateWeatherPattern . WeatherPattern( wea . Weather , kind )
	
	wep . WeatherPattern = New WeatherPattern
	
	wep \ Sprite = CreateSprite()
	EntityTexture wep \ Sprite , wea \ PatternTextures[ kind ]
			
	If kind = 1
				
		EntityAlpha wep \ Sprite, 0
		ScaleSprite wep \ Sprite , .5 , .5
		
		wep \ Frame = 0
		
		RL = Rnd( -1 , 0 )
		UD = Rnd( -1 , 0 )
		
		wep \ FaceRL = RL
		wep \ FaceUD = UD
		
		If wep \ FaceRL = 0 wep \ FaceRL = 1
		If wep \ FaceUD = 0 wep \ FaceUD = 1
		
		RotateEntity wep \ Sprite , EntityPitch( wea \ Camera ) , EntityYaw( wea \ Camera ) , EntityRoll( wea \ Camera )
		PositionEntity wep \ Sprite , EntityX( wea \ Camera ) , EntityY( wea \ Camera ) , EntityZ( wea \ Camera )
		MoveEntity wep \ Sprite , Rnd( -10 , 10 ) , Rnd( -8 , 8 ) , Rnd( 5 , 20 )
		
		
	Else If kind = 2
	
		EntityAlpha wep \ Sprite, 1
		
		wep \ Frame = 0
		wep \ FaceRL# = Rnd( .1 , .25 )
		
		RotateEntity wep \ Sprite , EntityPitch( wea \ Camera ) , EntityYaw( wea \ Camera ) , EntityRoll( wea \ Camera )
		PositionEntity wep \ Sprite , EntityX( wea \ Camera ) , EntityY( wea \ Camera ) , EntityZ( wea \ Camera )		
		MoveEntity wep \ Sprite , Rnd( -10 , 30 ) , 10 , Rnd( -5 , 20 )
		
	Else If kind = 3
		
		EntityAlpha wep \ Sprite, Rnd( .7 , .9 )
		ScaleSprite wep \ Sprite , Rnd( .4 , .5 ) , Rnd( .4 , .5 )
		
		wep \ Frame = 0
		wep \ FaceRL# = Rnd( 0.02 , .05 )
		wep \ FaceUD# = Rnd( -0.05 , -.125 )
		
		RotateEntity wep \ Sprite , EntityPitch( wea \ Camera ) , EntityYaw( wea \ Camera ) , EntityRoll( wea \ Camera )
		PositionEntity wep \ Sprite , EntityX( wea \ Camera ) , EntityY( wea \ Camera ) , EntityZ( wea \ Camera )	
		
		MoveEntity wep \ Sprite , Rnd( -20.5 , 10 ) , 10 , Rnd( -5 , 30 )
				
	Else If kind = 4
	
		ScaleSprite wep \ Sprite , 2 , 2
		EntityAlpha wep \ Sprite, 0.25
	
		wep \ FaceRL# = Rnd( 0.25 + amount / 100 , .5 + amount / 100 )
		
		RotateEntity wep \ Sprite , EntityPitch( wea \ Camera ) , EntityYaw( wea \ Camera ) , EntityRoll( wea \ Camera )
		PositionEntity wep \ Sprite , EntityX( wea \ Camera ) , EntityY( wea \ Camera ) , EntityZ( wea \ Camera )	
		
		MoveEntity wep \ Sprite , 10 , Rnd( -4 , 4 ) , Rnd( -5 , 10 )
				
	Else If kind = 5
	
		UpDown = Rnd( False, True )
		
		RotateEntity wep \ Sprite , EntityPitch( wea \ Camera ) , EntityYaw( wea \ Camera ) , EntityRoll( wea \ Camera )
		PositionEntity wep \ Sprite , EntityX( wea \ Camera ) , EntityY( wea \ Camera ) , EntityZ( wea \ Camera )
	
		If UpDown	
			MoveEntity wep \ Sprite , Rnd( -6 , 5 ) , - Rnd( 3 , 4 ) , Rnd( 5 , 8 )
			wep \ FaceUD = 1
		Else
			MoveEntity wep \ Sprite , Rnd( -6 , 5 ) , + Rnd( 3 , 4 ) , Rnd( 5 , 8 )
			wep \ FaceUD = -1
		EndIf
		
		ScaleSprite wep \ Sprite , 0 , 0
		EntityAlpha wep \ Sprite, 0
		
	Else If kind = 6
	
		EntityAlpha wep \ Sprite, 0
		ScaleSprite wep \ Sprite , 2 , 2
		
		wep \ Frame = 0
		
		RotateEntity wep \ Sprite , EntityPitch( wea \ Camera ) , EntityYaw( wea \ Camera ) , EntityRoll( wea \ Camera )
		PositionEntity wep \ Sprite , EntityX( wea \ Camera ) , EntityY( wea \ Camera ) , EntityZ( wea \ Camera )
		MoveEntity wep \ Sprite , Rnd( -5 , 5 ) , Rnd( -4 , 4 ) , Rnd( -5 , 10 )
				
	Else If kind = 7
	
		EntityAlpha wep \ Sprite, 1
				
		wep \ Frame = 0
		wep \ FaceRL# = Rnd( .1 , .25 )
		
		RotateEntity wep \ Sprite , EntityPitch( wea \ Camera ) , EntityYaw( wea \ Camera ) , EntityRoll( wea \ Camera )
		PositionEntity wep \ Sprite , EntityX( wea \ Camera ) , EntityY( wea \ Camera ) , EntityZ( wea \ Camera )	
		MoveEntity wep \ Sprite , Rnd( -15 , 30 ) , 10 , Rnd( -5 , 20 )
				
	End If	
	
	wep \ kind = kind
	
	Return wep
	
End Function

Function UpdatePatterns( wea . Weather )

	For wep . WeatherPattern = Each WeatherPattern
	
		If wep \ Kind = 1
		
			EntityAlpha wep \ Sprite, Sin ( wep \ Frame ) / 1.5	
			MoveEntity wep \ Sprite, wep \ FaceRL * Sin ( wep \ Frame ) / 500 , wep \ FaceUD * Cos ( wep \ Frame ) / 500 , 0
			wep \ Frame = wep \ Frame + .25
			
			If wep \ Frame > 180
				
				FreeEntity wep \ Sprite
				Delete wep.WeatherPattern
				
			EndIf
			
		Else If wep \ Kind = 2
		
			MoveEntity wep \ Sprite, -wep \ FaceRL , -wep \ FaceRL , 0
			wep \ Frame = wep \ Frame + 1
			
			If wep \ Frame > 120
				
				FreeEntity wep \ Sprite
				Delete wep.WeatherPattern
				
			EndIf
		
		Else If wep \ Kind = 3
			
			MoveEntity wep \ Sprite, wep \ FaceRL , wep \ FaceUD , 0
						
			If EntityY( wep \ Sprite ) < EntityY( wea \ Camera ) - 6
				
				FreeEntity wep \ Sprite
				Delete wep.WeatherPattern
				
			EndIf
			
		Else If wep \ Kind = 4
		
			MoveEntity wep \ Sprite, -wep \ FaceRL , 0 , 0
			
			If EntityX( wep \ Sprite ) < EntityX( wea \ Camera ) - 5
				
				FreeEntity wep \ Sprite
				Delete wep.WeatherPattern
				
			EndIf
			
		Else If wep \ Kind = 5
		
			wep \ Frame = wep \ Frame + 1
		
			If wep \ Frame < 361
		
			EntityAlpha wep \ Sprite, Abs( Sin ( wep \ Frame - 90 ) ) / 1.5	
			ScaleSprite wep \ Sprite, Abs( Sin ( wep \ Frame - 90 ) ) , Abs( Sin ( wep \ Frame - 90 ) )
		
			MoveEntity wep \ Sprite, Sin( wep \ Frame ) / 100 , wep \ FaceUD * Cos( wep \ Frame ) / 100 , 0
						
			Else
			
				EntityAlpha wep \ Sprite, .5
				ScaleSprite wep \ Sprite, .5 , .5
				
				MoveEntity wep \ Sprite, 0 , wep \ FaceUD / 20 , 0
				
				If wep \ Frame > 500
				
					FreeEntity wep \ Sprite
					Delete wep.WeatherPattern
					
				EndIf
				
			EndIf
			
		Else If wep \ Kind = 6
				
			EntityAlpha wep \ Sprite, Sin( wep \ Frame ) / 5
			
			wep \ Frame = wep \ Frame + 2
		
			If wep \ Frame > 180
				
				FreeEntity wep \ Sprite
				Delete wep.WeatherPattern
				
			EndIf
			
		Else If wep \ Kind = 7
		
			MoveEntity wep \ Sprite, -wep \ FaceRL * .75 , -wep \ FaceRL , 0
			wep \ Frame = wep \ Frame + 1
			
			If wep \ Frame > 80
				
				FreeEntity wep \ Sprite
				Delete wep.WeatherPattern
				
			EndIf
			
		EndIf
		
	Next
		
	wea \ PatternCount = wea \ PatternCount + wea \ amount
	
	If wea \ Name = "GlowingAir"
	
		If wea \ PatternCount > 20
	
			For i = 0 To 0
		
				CreateWeatherPattern( wea , 1 )
				
			Next
			wea \ PatternCount = 0
		
		EndIf	
	
	Else If wea \ Name = "Rain"
	
		If wea \ PatternCount > 20
	
			For i = 0 To 10
		
				CreateWeatherPattern( wea , 2 )
				
			Next
			wea \ PatternCount = 0
		
		EndIf	
	
	Else If wea \ Name = "Snow"
	
		If wea \ PatternCount > 20
	
			For i = 0 To 10
		
				CreateWeatherPattern( wea , 3 )
				
			Next
			wea \ PatternCount = 0
		
		EndIf	
		
	Else If wea \ Name = "Wind"
	
		If wea \ PatternCount > 20
	
			For i = 0 To 5
		
				CreateWeatherPattern( wea , 4 )
				
			Next
			wea \ PatternCount = 0
		
		EndIf	
		
	Else If wea \ Name = "NatureBalls"
	
		If wea \ PatternCount > 20
	
			For i = 0 To 0
		
				CreateWeatherPattern( wea , 5 )
				
			Next
			wea \ PatternCount = 0
		
		EndIf	
	
	Else If wea \ Name = "Mist"
	
		If wea \ PatternCount > 20
	
			For i = 0 To 0
		
				CreateWeatherPattern( wea , 6 )
				
			Next
			wea \ PatternCount = 0
		
		EndIf	
		
	Else If wea \ Name = "Hail"
	
		If wea \ PatternCount > 20
	
			For i = 0 To 5
		
				CreateWeatherPattern( wea , 7 )
				
			Next
			wea \ PatternCount = 0
		
		EndIf	
	
	EndIf
	

End Function